package com.xy.dp.composite;

import java.util.ArrayList;
import java.util.List;

public class Files implements Component {
    private String name;
    private List<Component> children = new ArrayList<>();

    public Files(String  name) {
        this.name = name;
    }
    @Override
    public void add(Component c) {
        children.add(c);
    }

    @Override
    public void remove(Component c) {
        children.remove(c);
    }

    @Override
    public void display(int depth) {
        System.out.println("depth: " + getLines(depth) + " " + name);
        for (Component component: children) {
            component.display(depth + 1);
        }
    }

    private String getLines(int depth) {
        String lines = "";
        for (int i = 0; i < depth; i++) {
            lines += "-";
        }
        return lines;
    }
}
